<?php
header("Content-Type: text/html; charset=utf-8");
session_start();

error_reporting(E_ALL);
ini_set('display_errors', 1);
use Auth\Auth;

require 'auth.php';
$em = require __DIR__ . '/example/em.php';

// проверка залогинен ли юзер
$auth = new Auth($em);
if ($auth->isAuth()) {
    //echo 'test';    
} else {
    header("Location: login.php");
}
$user = $auth->getUser();
$manager = new Service\UserManager($em);
$sumAgentBalance = $manager->getSumAgentBalance($user);

//  вся процедура работает на сессиях. Именно в ней хранятся данные  пользователя, пока он находится на сайте. Очень важно запустить их в  самом начале странички!!!

require 'template/menu.html';
$page = !empty($_GET['page']) ? $_GET['page'] : null;
switch ($page) {
    case 'usloviya':
        require 'template/usloviya.html';
        break;
    case 'detail':
        require 'template/detail.php';
        break;
    case 'accruals':
        require 'template/accruals.php';
        break;
    case 'bonus_calculation':
        require 'template/bonus_calculation.html';
        break;        
    case 'history':
        require 'template/history.php';
        break;
    case 'contact':
        require 'template/contact.html';
        break;
    case 'all_user_profile':
        require 'template/all_user_profile.php';
        break;
    case 'manage_level':
        require 'template/manage_level.php';
        break;
    case 'refill':
        require 'template/refill.php';
        break;
    case 'create_user':
        echo '<!-- switch buttons -->';
        echo '<link rel="stylesheet" href="template/js/lib/ibutton/css/jquery.ibutton.css">';
        echo '<script src="template/js/lib/ibutton/js/jquery.ibutton.beoro.min.js"></script>';
        echo '<!-- password strength metter -->';
        echo '<script src="template/js/lib/pwdMeter/jquery.pwdMeter.js"></script>';
        require 'template/create_user.html';
        break;
//Begin Grafics
    case 'charts_country':
        require 'template/charts_country.php';
        break;
    case 'charts_out_operator':
        require 'template/charts_out_operator.php';
        break;
    case 'charts':
        require 'template/charts.php';
        break;
    case 'table_oborot':
        require 'template/charts_oborot.php';
        require 'template/table_oborot.php';
        break;
    case 'table_call_out':
        require 'template/table_call_out.php';
        break;
    case 'charts_cart_active':
        require 'template/charts_cart_active.php';
        break;
    case 'table_call_in':
        require 'template/table_call_in.php';
        break;
    case 'table_in_min':
        require 'template/table_in_min.php';
        break;
    case 'table_out_min':
        require 'template/table_out_min.php';
        break;
//End Grafics
    case 'create_sim':
        require 'template/create_sim.php';
        break;
    case 'login_user_histoty':
        require 'template/login_user_histoty.php';
        break;
    case 'sim_manager':
        echo '<!-- switch buttons -->';
        echo '<!-- 2 col multiselect -->';
        echo '<!-- enchanced select box, tag handler -->';
        echo '<link rel="stylesheet" href="template/js/lib/select2/select2.css">';
        require 'template/sim_manager.php';
        echo '<!-- 2col multiselect -->';
        echo '<!-- masked inputs -->';
        echo '<script src="template/js/lib/jquery-inputmask/jquery.inputmask.min.js"></script>';
        echo '<script src="template/js/lib/multi-select/js/jquery.multi-select.min.js"></script>';
        echo '<script src="template/js/lib/multi-select/js/jquery.quicksearch.min.js"></script>';
        break;
    case 'user_profile':
        echo '<!-- Mockjax -->';
        echo '<script src="template/js/jquery.mockjax.js"></script>';
        echo '<!-- x-editable -->';
        echo '<script src="template/js/lib/x-editable/bootstrap-editable/js/bootstrap-editable.min.js"></script>';
        echo '<!-- password strength metter -->';
        echo '<script src="template/js/lib/pwdMeter/jquery.pwdMeter.js"></script>';

        echo '<script src="template/js/pages/beoro_editable_elements.js"></script>';
        require 'template/user_profile.html';
        break;
    default:
        require 'template/index.php';
        break;
}
require 'template/footer.html';
?>
